/*
 * @Author: Dagon
 * @Date: 2021-03-01 20:08:52
 * @Description: 防抖与截流
 */
  
 // 防抖函数
 function debunce(fn, delay) {
   let flag = null
   return function () {
     if (flag) clearTimeout(flag)
     flag = setTimeout(() => {
       fn.apply(this, arguments)
     }, delay);
   }
 }

 // 截流函数
 function throttle(fn, delay) {
   let flag = null
   if (!flag) {
     flag = setTimeout(() => {
       fn.apply(this, arguments)
       flag = null;
     }, delay);
   }
 }